<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改高峰论坛')" />
    <th:block th:include="include :: tinymce"/>
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-content-edit" th:object="${cmsContent}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">标题：</label>
            <div class="col-sm-8">
                <textarea name="title" class="form-control" placeholder="高峰论坛标题">[[*{title}]]</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">概要：</label>
            <div class="col-sm-8">
                <textarea name="brief" class="form-control" placeholder="内容的概要">[[*{brief}]]</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">内容：</label>
            <div class="col-sm-8">
                <textarea class="summernote" id="content" name="content" th:field="*{content}"></textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">排序：</label>
            <div class="col-sm-8">
                <input name="idx" th:field="*{idx}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">论坛时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="ext1" type="text" th:field="*{ext1}" class="form-control" id="datetimepicker-demo-1" placeholder="yyyy.MM.dd">
                </div>
            </div>
        </div>
        <div class="form-group">
            <input name="thumb" id="thumb" th:field="*{thumb}" class="form-control" type="hidden">
            <label class="col-sm-3 control-label ">图片</label>
            <div class="col-sm-8">
                <input id="singleFile" name="file" type="file">
            </div>
        </div>

        <div class="box-footer">
            <div class="col-sm-offset-5 col-sm-6">
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<script th:inline="javascript">
    var prefix = ctx + "news/content";
    var imgUrl =  [[${cmsContent.thumb}]]
    var initialPreview = []

    if(imgUrl) {
        initialPreview = [base+imgUrl]
    }

    $("#form-content-edit").validate({
        rules: {
            title: "required",
            idx: "required"
        },
        messages: {
            title:  "必填项",
            idx:  "必填项"
        }
    });

    layui.use('laydate', function() {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#datetimepicker-demo-1',
            format: "yyyy.MM.dd",
        });
    })

    $("#singleFile").fileinput({
        uploadUrl: ctx + 'common/upload',
        maxFileCount: 1,
        autoReplace: true,
        initialPreviewAsData: true,
        initialPreview: initialPreview
    }).on('fileuploaded', function (event, data, previewId, index) {
        var rsp = data.response;

        $('#thumb').val(rsp.fileName)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    }).on('filedeleted', function() {
        $('#thumb').val('')
    }).on('filesuccessremove', function() {
        $('#thumb').val('')
    }).on('filecleared', function() {
        $('#thumb').val('')
    })

    function submitHandler() {
        $('#content').val(tinyMCE.get('content').getContent())
        if ($.validate.form()) {
            $.operate.saveTab(prefix + "/edit", $('#form-content-edit').serialize());
        }
    }

    $(function() {
        initTinyMec('#content')
    });
</script>
</body>
</html>